///
/// ArmyBodger 3
/// (c)2010 richyp
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArmyBodger.Core {
    /// <summary>
    /// A Collection of Entry objects
    /// </summary>
    public class EntryCollection : List<Entry> {
        /// <summary>
        /// Indexer to retreive an Entry object by name
        /// </summary>
        /// <param name="name">Name of the Entry object to retrieve</param>
        /// <returns>Entry object provided by "name" or null</returns>
        public Entry this[string name] {
            get {
                foreach (Entry entry in this) {
                    if (entry.Name == name) {
                        return entry;
                    }
                }
                return null;
            }
        }
        /// <summary>
        /// Return a collection of Entry objects with the matching name
        /// </summary>
        /// <param name="name">The name to match</param>
        /// <returns>A collection of Entry objects</returns>
        public EntryCollection GetEntriesByName(string name) {
            EntryCollection results = new EntryCollection();
            foreach (Entry entry in this) {
                if (entry.Name == name) {
                    results.Add(entry);
                }
            }
            return results;
        }
        /// <summary>
        /// Get a collection of Entry objects belonging to a specific 
        /// category
        /// </summary>
        /// <param name="category">The category to retreive</param>
        /// <returns>A Collection of Entry objects belonging to "category"</returns>
        public EntryCollection GetEntriesByCategory(string category) {
            EntryCollection results = new EntryCollection();
            foreach (Entry entry in this) {
                if (entry.Category == category) {
                    results.Add(entry);
                }
            }
            return results;
        }
        /// <summary>
        /// Copy this collection
        /// </summary>
        /// <returns>A new copy of this collection and its items</returns>
        public EntryCollection Copy() {
            return EntryCollection.Copy(this);
        }
        /// <summary>
        /// Static copy method to create a new copy of the provided collection
        /// </summary>
        /// <param name="source">The original collection</param>
        /// <returns>A new copy of this collection and its items</returns>
        public static EntryCollection Copy(EntryCollection source) {
            EntryCollection results = new EntryCollection();
            foreach (Entry entry in source) {
                results.Add(entry.Copy());
            }
            return results;
        }
    }
}
